Back to course home
0% completed
Vote For New Content
LinkedIn Hard
Max Points on a Line (hard)
Solution: Max Points on a Line
Closest Binary Search Tree Value II (hard)
Solution: Closest Binary Search Tree Value II
Word Ladder (hard)
Solution: Word Ladder
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Largest Rectangle in Histogram (hard)
Solution: Largest Rectangle in Histogram
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
Valid Parenthesis String (medium)
Problem Statement
Given a string s containing multiple occurrences of characters: '(', ')' and '*', return true if s is valid. Otherwise, return false.
A string is valid if it follows below rules:
- Any left parenthesis
'('must be closed by corresponding right parenthesis ')'. - Any right parenthesis
')'must have a corresponding left parenthesis'('. '*'can be used as a single left parenthesis')'or a single right parenthesis'('or an empty string"".
Examples
-
Example 1:
- Input: s=
"*())" - Expected Output:
true - Justification: The asterisk can be treated as an open parenthesis, making the string "(())."
- Input: s=
-
Example 2:
- **Input: s =
"((*()**" - Expected Output:
true - **Justification: The first and second asterisks can be treated as close parenthesis, and the third asterisk can be treated as an empty string, resulting in a balanced set of parentheses "(()())."
- **Input: s =
-
Example 3:
- Input: s =
"())*" - Expected Output:
false - Justification: There's no way to interpret the asterisk that would balance the extra close parenthesis at the start.
- Input: s =
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Valid Triangle Number
Solution: Valid Parenthesis String
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself